import { createRouter, createWebHistory } from "vue-router";
import { getToken } from "../utils/token-utils";
import ContentTest from '../pages/ContentTest.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "contentTest",
    },
    {
      name: "contentTest",
      path: "/contenttest",
      component: ContentTest,
    },
  ],
});

//全局前置守卫
router.beforeEach((to, from, next) => {
  const token = getToken();
  if (token) {
    if (to.path == "/login" || to.path == "/register") {
      next({ path: "/" });
    } else {
      next();
    }
  } else {
    next();
  }
});

//全局后置守卫

export default router;
